﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <link rel="stylesheet" href="Console/styles/main-styles.css" />
    <link href="Console/styles/js-console.css" rel="stylesheet" />
</head>
<body>
    <h3>Write a function that replaces non breaking white-spaces in a text with &nbsp;
</h3>
    <label for="tb-first">Input text: </label>
    <input type="text" id="tb-second" />
    <div id="wrapper">
        <br />
        <a href="#" onclick="runProgram()">Run program!</a>
        <div id="console">
        </div>
    </div>
    <script src="Console/scripts/js-console.js">	  
	</script>
    <script>

        // Gets the user input

        function getText() {
            var text = document.getElementById('tb-second').value;
            return text;
        }

        // Bracket checker
        function whitespaceReplace(text, symbol) {
            var outStr = "";
            for (var i = 0; i < text.length; i++) {
                if (text[i] === " ") {
                    outStr += symbol;
                }
                else {
                    outStr += text[i];
                }
            }

            return outStr;
        }

        //run program
        function runProgram() {
            var text = getText();
            jsConsole.writeLine(whitespaceReplace(text, "WTF;"));
        }
	</script>
</body>
</html>
